<?php

/**
 * MVM_MALL 网上商店系统  广告条管理
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-09-03 $
 * $Id: banner.inc.php  www.mvmmall.com$
 * ---------------------------------------------
*/

if(!defined('MVMMALL') || !defined('IN_ADMINCP')) exit('Access Denied');
$ad_arr  = array(
''=>'',
'top_logo'=>'顶部LOGO',
'bottom_logo'=>'底部LOGO',
'bottom_logo'=>'底部LOGO',
'banner'=>'banner',
'list_gg1'=>'广告1',
'list_gg2'=>'广告2',
'list_gg3'=>'广告3',
'list_gg4'=>'广告4',
'list_gg5'=>'中部广告1',
'list_gg6'=>'中部广告2',
'list_gg7'=>'中部广告3',
'list_gg8'=>'中部广告4',
'list_gg9'=>'中部广告5',
);
$target = array('_blank'=>'_blank','_parent'=>'_parent','_self'=>'_self','_top'=>'_top');
//列
if ($action=='list')
{
    require_once 'include/pager.class.php';
    $total_count = $db->counter("{$tablepre}banner_table");
    $page        = $page ? (int)$page:1;
    $list_num    = 10;
    $rowset      = new Pager($total_count,$list_num,$page);
    $from_record = $rowset->_offset();
    $result      = $db->query("SELECT * FROM `{$tablepre}banner_table` ORDER BY uid DESC LIMIT $from_record,$list_num ");
    while ($rt   = $db->fetch_array($result)) {
        $rt['start_date']  = date($mm_date_format, $rt['start_date']);
        $rt['end_date']    = date($mm_date_format, $rt['end_date']);
        $rt['edit']        = "admincp.php?module=$module&action=edit&uid=$rt[uid]";
        $rt['del']         = "admincp.php?module=$module&action=del&uid=$rt[uid]";
        $rt['url']         = "auction.php?action=view&id=$rt[act_id]";
        $ad_rt[]           = $rt;
    }
    $page_list   = $rowset->link("admincp.php?module=$module&action=$action&ps_or=$ps_or&ps_ac=$ps_ac&ps_subject=$ps_subject&ps_code=$ps_code&ps_class=$ps_class&page=");
    $js_url      = MVMMALL_DIR.'/api/javascript.php';
    include template('banner');
    footer();
}

//添加
elseif ($action=='add'){
    if($setp==1&&$_POST){
    	//图片
    	if ($_FILES['banner_file1']['name']!=''){
    		require_once MVMMALL_ROOT.'./include/upfile.class.php';
    		$f = new upfile('gif,jpg,png,bmp,swf','./images/banner/');
    		$banner_file1_text = $f->upload('banner_file1');
    	}
        $start_date = time_format($start_date );
        $end_date   = time_format($end_date);
        $row = array(
        'banner_point'   => $banner_point,
        'banner_class'   => $banner_class,
        'banner_weight'  => $banner_weight,
        'banner_subject' => $banner_subject,
        'banner_width'   => $banner_width,
        'banner_height'  => $banner_height,
        'banner_file1'   => $banner_file1_text,
        'banner_link1'   => $banner_link1,
        'banner_body'    => $banner_body,
        'banner_url'     => $banner_url,
        'banner_target'  => $banner_target,
        'start_date'     => $start_date,
        'end_date'       => $end_date,
        'register_date'  => $m_now_time
        );
        $db->insert("{$tablepre}banner_table",$row);
        file_unlink(MVMMALL_CACHE.'banner_array.cache.php');
        admin_msg('success','admincp.php?module=banner&action=list');
    }else {
    	$banner_class = 0;
        $ad_menu     = drop_menu($ad_arr,'ad_select');
        $target_menu = drop_menu($target,'banner_target');
        require template('banner_add');
        footer();
    }
}

//编辑
elseif ($action=='edit' && is_numeric($uid)){
    if($setp==1&&$_POST){
        //图片
        if ($_FILES['banner_file1']['name']!=''){
            require_once 'include/upfile.class.php';
            $f = new upfile('gif,jpg,png,bmp,swf','./images/banner/');
            file_unlink($banner_file1_text);//删除图片
            $banner_file1_text = $f->upload('banner_file1');
        }
        $start_date = time_format($start_date );
        $end_date   = time_format($end_date);
        $row = array(
        'banner_point'   => $banner_point,
        'banner_class'   => $banner_class,
        'banner_weight'  => $banner_weight,
        'banner_subject' => $banner_subject,
        'banner_width'   => $banner_width,
        'banner_height'  => $banner_height,
        'banner_file1'   => $banner_file1_text,
        'banner_link1'   => $banner_link1,
        'banner_body'    => $banner_body,
        'banner_url'     => $banner_url,
        'banner_target'  => $banner_target,
        'start_date'     => $start_date,
        'end_date'       => $end_date
        );
        $db->update("{$tablepre}banner_table",$row,"uid='$uid'");
        file_unlink(MVMMALL_CACHE.'banner_array.cache.php');
        admin_msg('success','admincp.php?module=banner&action=list');
    } else {
        $rt = $db->get_one("SELECT * FROM `{$tablepre}banner_table` WHERE uid = '$uid'");
        @extract($rt,EXTR_OVERWRITE);
        $start_date = date('Y-m-d',$start_date);
        $end_date   = date('Y-m-d',$end_date);
        $ad_menu     = drop_menu($ad_arr,'ad_select',$banner_point);
        $target_menu = drop_menu($target,'banner_target',$banner_target);
        include template('banner_add');
        footer();
    }
}
//删除图片
elseif ($action=='del' && is_numeric($uid)){
    $rt = $db->get_one("SELECT uid,banner_file1 FROM {$tablepre}banner_table WHERE uid = '$uid'");
    $rt['banner_file1'] &&  file_unlink($rt['banner_file1']);
    $db->query(" DELETE FROM {$tablepre}banner_table WHERE uid='$uid'");
    file_unlink(MVMMALL_CACHE.'banner_array.cache.php');
} else {
    admin_msg('pass_worng');
}
